import {Component, ViewChild} from '@angular/core';
import {Router} from "@angular/router";
import {routes} from "./routes";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
  menus=[{content:'&#xea40;'},{content:'&#xea3c;'},{content:'&#xe911;'}];
  @ViewChild("audio") audio;
  constructor(private router:Router){

  }
  menuClicked(index:number){
    let url:string=this.router.url;
    let mi=0;
    if(url=="/") {
      mi=0;
    }else{
      for(let rt in routes){
        if(!routes[rt].path) continue;
        if(url.indexOf(routes[rt].path)>=0) {
          mi=parseInt(rt);
          break;
        }
      }
    }
    switch (index){
      case 0:
        if(mi==0) return;
        this.router.navigateByUrl(routes[mi-1].path);
        break;
      case 1:
        if(mi==routes.length-1) return;
        this.router.navigateByUrl(routes[mi+1].path);
        break;
      case 2:
        let el=this.audio.nativeElement;
        if(el.paused){
          el.play();
        }else{
          el.pause();
        }
    }
  }
  next(d){
    console.log(d);
    let url:string=this.router.url;
    let mi=0;
    if(url=="/") {
      mi=0;
    }else{
      for(let rt in routes){
        if(!routes[rt].path) continue;
        if(url.indexOf(routes[rt].path)>=0) {
          mi=parseInt(rt);
          break;
        }
      }
    }
    if(mi==routes.length-1) return;
    this.router.navigateByUrl(routes[mi+1].path);
  }
  previous(d){
    console.log(d);
    let url:string=this.router.url;
    let mi=0;
    if(url=="/") {
      mi=0;
    }else{
      for(let rt in routes){
        if(!routes[rt].path) continue;
        if(url.indexOf(routes[rt].path)>=0) {
          mi=parseInt(rt);
          break;
        }
      }
    }
    if(mi==0) return;
    this.router.navigateByUrl(routes[mi-1].path);
  }
}
